<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else

    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
       
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());

if ($_GET['action'] == 'edit') {
    
    $qry = "select * from maintenance where user_id='".$_SESSION['uid']."' and m_date='".$_GET['m_date']."'";
    
    $results = mysql_query($qry)or die(mysql_error($con));

    extract(mysql_fetch_assoc($results));
    
}else {
    //set values blanks
    $type = ''; 
    $notes = '';
    
    //Date variables
    $day = 0;
    $month = 0;
    $year = 0;
   
    
    //Function to make a valid date input
    $m_date = $year."-".$month."-".$day;
    
    list($year, $month, $day) = explode("-", $date_setup);
}

?>

<html>
<head>
    
    <title><?php echo ucfirst($_GET['action']); ?>Maintenance</title>
    <link rel="stylesheet" type="text/css" href="http://localhost/ReefersLogApp/CSS/Generalpagelayout.css" />
    
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
    <script type='text/javascript' src='./../scripts/js/jquery.ba-hashchange.min.js'></script>
    <script type='text/javascript' src='./../scripts/js/dynamicpage.js'></script>
    
</head>
<div id="container">
	<div id="header">
            <h1>
		Reefers Log
            </h1>
	</div>
	<div id="navigation">
		<ul>
			<li><a href="./../WelcomePage/WelcomePage.php">Home</a></li>
			<li><a href="./../Profile/userprofile.php">Profile</a></li>
			<li><a href="./../Tools/tools.php">Tools</a></li>
			<li><a href="./../Logout/logout.php">Logout</a></li>
		</ul>
	</div>
	<div id="content-container">
		<div id="section-navigation">
                    <object id="loader" name="frameloader" type="text/html" data="http://localhost/ReefersLogApp/Welcome/WelcomePage.php/"></object>
			<ul>
                           
				<li><a href="waterchange.html">Water Change</a></li>
				<li><a href="./../Test_Logs/watertest.html">Water Tests</a></li>
                                <li><a href="waterchangelog.php">View Water Change Log</a></li>
                                <li><a href="maintenancelog.php">View Maintenance Log</a></li>
				
			</ul>
		</div>
		<div id="content">
                    <h2>
                        Your Aquarium Statistics:
                    </h2>
                    <p>
                        Update your maintenance logging regarding your aquarium. You may complete the form below or select another option
                        from the menu on the left.
                    </p>
		</div>
            <div id="content">
                    <h2>
                        Update the form below:
                    </h2>

<div align="center">

    <form action="commitedit.php?action=<?php echo $_GET['action']?>&type=mait&m_date=<?echo $_GET['m_date']?>" method="post">

        <table width="80%" cellpadding="0" cellspacing="0" border="1">
                </tbody>
                           
                            <tr>                               
                                    <td>You can not edit the date of the maintenance activity!</br>Date:
                                    <input type="text" name="date" value="<?echo "$m_date"?>" readonly="readonly"</td>
                            </tr>
                            <tr>
                                <td><label>Type:</label> <input type="text" name="cost" value="<? echo "$type"?>" /></td>
                                <td>Notes:</br><textarea name="notes" rows="4" cols="20" >
                                
                                    <?= $notes?>
                            
                                </textarea>
                                </td>
                            </tr>                                                        
</tbody>
</table>
        <input align="center" type="submit" value="Edit Maintenance" name="Edit Maintenance" />
        
</div>
</form>
</div>
		<div id="aside">
                    <h3>
                        Info:
                    </h3>
                    <p>Track your husbandry activity through this form</p>
		</div>
		<div id="footer">
			Copyright © ReefersLog, 2012, wkoester All Rights Reserved
		</div>
	</div>
</div>
</html>